package com.imooc.web.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.imooc.web.filter.TimeFilter;
import com.imooc.web.interceptor.TimeInterceptor;

/**
 * 3.7.5 添加WebConfig类
 * @author qilongfei
 *
 */
@Configuration
// 3.7.11 继承WebMvcConfigAdapter用于配置拦截器
public class WebConfig extends WebMvcConfigurerAdapter{
	
	@Autowired
	private TimeInterceptor timeInterceptor;
	
	/**
	 * 3.7.12 注册自定义Interceptor
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// registry.addInterceptor(timeInterceptor);
	}

	/**
	 * 3.7.6 注册自定义Filter
	 * @return
	 */
	// @Bean
	public FilterRegistrationBean timeFilter(){
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		TimeFilter timeFilter = new TimeFilter();
		registrationBean.setFilter(timeFilter);
		
		List<String> urls = new ArrayList<>();
		urls.add("/*");
		registrationBean.setUrlPatterns(urls);
		return registrationBean;
	}
	
	/**
	 * 3.10.8 注册异步请求拦截器
	 */
	/*@Override
	public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
		// configurer.registerCallableInterceptors(interceptors);
		// configurer.registerDeferredResultInterceptors(interceptors)
	}*/
}
